package com.kobe.algorithm.leetcode.case1;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author ：caopengfei
 * @date ：2021/2/22
 */
public class Solution {
    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer,Integer> numMaps = new HashMap<>();
        for(int i = 0; i < nums.length ;i++){
            numMaps.put(nums[i],i);
        }
        for(int j = 0 ; j<nums.length ; j++){
            int key = target - nums[j];
            if(numMaps.containsKey(key) && numMaps.get(key) != j){
                return new int[]{j, numMaps.get(key)};
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int [] nums = {3,2,4};
        System.out.println(Arrays.toString(twoSum(nums,6)));
    }
}
